<template>
  <view class="boxbig">
    <view id="box">
      <view class="timu" v-for="(item, index) in param" :key="index">
        <view class="timu_title">
          {{ `${index + 1}.${item.topicName}` }}
        </view>
        <view class="" style="padding: 10px;">
          <u-radio-group v-model="item.isChecked" placement="column" @change="groupChange">
            <u-radio :customStyle="{ marginBottom: '8px' }" v-for="item2 in item.AnswerList"
                     :key="item2.selectedId" :label="item2.option" :name="item2.selectedId"
                     @change="radioChange">
            </u-radio>
          </u-radio-group>
        </view>

      </view>
    </view>
    <u-button type="primary" text="提交" @click="handlequeding"></u-button>
    <u-toast ref="uToast"></u-toast>
  </view>

</template>

<script>
import {
  baseUrl
} from '../../utils/config.js';

export default {
  data() {
    return {
      param: "",
      rows: "",
      param1: "",
      // 基本案列数据
    }
  },
  onLoad(options) {
    this.chaxunxiangqing(options.id)
    this.rows=options.id

  },
  methods: {
    chaxunxiangqing(id){
      let that=this
      uni.request({
        url: `${baseUrl}/wechat/InfoQuestionNaireLog/${id}`,
        method: 'GET',
        success(res) {
          that.param=JSON.parse(res.data.data.questionContent)
          that.param1=res.data.data.questionTitle
        }
      })
    },
    groupChange(e) {
      console.log(e, "x")
    },
    radioChange(e) {

    },
    handlequeding() {
      let item = this.param
      let that=this
      for (let i = 0; i < item.length; i++) {
        console.log(item[i].isChecked, "111")
        if (item[i].isChecked==undefined) {
          that.$refs.uToast.show({
            type: 'default',
            message: "请填写完整",
          })
          return
        }
      }
      let data = {
        questionContent: JSON.stringify(this.param),
        questionId: that.rows,
        questionTitle: this.param1,
      }

      uni.request({
        url: `${baseUrl}/wechat/InfoQuestionNaireLog/submitNaireLog`,
        method: 'post',
        data: data,
        header: { taken: uni.getStorageSync('ykt_openId') },
        success(res) {
          that.$refs.uToast.show({
            type: 'default',
            message: "提交成功",
          })
          uni.switchTab({
            url: '/pages/special/index'
          });
        },

      });

    }
  }

}
</script>

<style scoped lang="scss">
.boxbig {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

#box {
  height: 90vh;
  overflow: auto;
  padding: 10px;

  .timu {
    .timu_title {}
  }
}
</style>